//
//  LHNumberView.m
//  lehuotest
//
//  Created by ice on 2017/1/4.
//  Copyright © 2017年 QF. All rights reserved.
//

#import "LHNumberView.h"

@interface LHNumberView()

@property (nonatomic, weak) IBOutlet UIButton *addBtn;

@property (nonatomic, weak) IBOutlet UIButton *subBtn;

@property (nonatomic, weak) IBOutlet UILabel *countLabel;

@property (nonatomic, assign) NSInteger curCount;
@end

@implementation LHNumberView




+(instancetype) loadFromNib
{
    NSString *xibName = NSStringFromClass([self class]);
    return [[[NSBundle mainBundle] loadNibNamed:xibName owner:nil options:nil] firstObject];
}
-(void) awakeFromNib
{
    [super awakeFromNib];
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 4.f;
    self.layer.borderColor = [UIColor blackColor].CGColor;
    self.layer.borderWidth = .5f;
    [self.addBtn addTarget:self action:@selector(addBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.subBtn addTarget:self action:@selector(subBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.curCount = 1;
    if(!self.maxCount){
        self.maxCount = 99;
    }
}
-(void) setMaxCount:(NSInteger)maxCount
{
    _maxCount = maxCount;
    
}
-(void) addBtnAction
{
    if (self.curCount >= self.maxCount){
        return;
    }
    self.curCount++;
    self.countLabel.text = [NSString stringWithFormat:@"%ld",(long)self.curCount];
}

-(void) subBtnAction
{
    if (self.curCount == 1){
        return ;
    }
    self.curCount--;
    self.countLabel.text = [NSString stringWithFormat:@"%ld",(long)self.curCount];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
